<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <!-- <link rel="stylesheet" type="text/css" href="style.css"> -->
  <style>
    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }

    body {
      display: flex;
      justify-content: center;
      align-items: center;
      height: 100vh;
    }

    .container {
      display: flex;
      justify-content: center;
      align-items: center;
    }

    .traffic-light {
      position: relative;
      width: 100px;
      height: 300px;
      background: #e2e2e2;
      border-radius: 20px;
      box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.3), 0 0 20px rgba(0, 0, 0, 0.3);
    }

    ul {
      list-style: none;
      width: 80px;
      height: 230px;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      position: absolute;
      top: 0;
      bottom: 0;
      left: 0;
      right: 0;
      margin: auto;
    }

    li {
      border-radius: 50%;
      width: 80px;
      height: 80px;
      background-color: #b3b3b3;
      box-shadow: 0 0 15px rgba(0, 0, 0, 0.1), 0 -10px 10px rgba(255, 255, 255, 0.3) inset, 0 10px 10px rgba(0, 0, 0, 0.2) inset;
      transition: background-color 0.2s ease-in-out;
    }

    .red {
      background-color: #ff4154;
      box-shadow: 0 0 15px rgba(0, 0, 0, 0.1), 0 -10px 10px rgba(255, 255, 255, 0.3) inset, 0 10px 10px rgba(0, 0, 0, 0.2) inset;
    }

    .red.active {
      background-color: #ff0000;
      box-shadow: 0 0 15px rgba(0, 0, 0, 0.1), 0 -10px 10px rgba(255, 255, 255, 0.3) inset, 0 20px 40px rgba(255, 0, 0, 0.9) inset, 0 0 10px rgba(0, 0, 0, 0.4);
    }

    .yellow {
      background-color: #f7d038;
    }

    .yellow.active {
      background-color: #ffff00;
      box-shadow: 0 0 15px rgba(0, 0, 0, 0.1), 0 -10px 10px rgba(255, 255, 255, 0.3) inset, 0 20px 40px rgba(255, 255, 0, 0.5) inset, 0 0 10px rgba(0, 0, 0, 0.4);
    }

    .green {
      background-color: #86bf35;
    }

    .green.active {
      background-color: #00ff00;
      box-shadow: 0 0 15px rgba(0, 0, 0, 0.1), 0 -10px 10px rgba(255, 255, 255, 0.3) inset, 0 20px 40px rgba(0, 255, 0, 0.5) inset, 0 0 10px rgba(0, 0, 0, 0.4);
    }
  </style>
</head>

<body>
  <div class="container">
    <div class="traffic-light">
      <ul>
        <li class="red"></li>
        <li class="yellow"></li>
        <li class="green"></li>
      </ul>
    </div>
  </div>
</body>
<script>

  function red() {
    return new Promise((resolve, reject) => {
      let i = 11
      document.querySelector('.red').classList.add('active')
      const redd = setInterval(() => {
        i--
        console.log(i);
        if (i === 0) {
          clearInterval(redd)
          document.querySelector('.red').classList.remove('active')
          return resolve(12)
        }
      }, 1000)
    })

  }
  function yellow() {
    return new Promise((resolve, reject) => {
      let i = 3
      document.querySelector('.yellow').classList.add('active')
      const redd = setInterval(() => {
        i--
        console.log(i);
        if (i === 0) {
          clearInterval(redd)
          document.querySelector('.yellow').classList.remove('active')
          return resolve(4)
        }

      }, 1000)

    })

  }
  function green() {
    return new Promise((resolve, reject) => {
      let i = 5
      document.querySelector('.green').classList.add('active')
      const redd = setInterval(() => {
        i--

        console.log(i);
        if (i === 0) {
          clearInterval(redd)
          document.querySelector('.green').classList.remove('active')
          return resolve(6)
        }

      }, 1000)

    })

  }

  async function color() {
    await red()
    await yellow()
    await green()
    color()
  }
  color()


</script>

</html>